/*
 * @Author: DUST
 * @Date: 2023-05-29 13:41:01
 * @LastEditors: DUST
 * @LastEditTime: 2023-06-06 17:57:27
 * @FilePath: \koa-node-ts\app\model\Note.ts
 * @Description: 
 * undefined
 */

import { Column, DataType, Model, Table } from "sequelize-typescript"

@Table({
  tableName: "Notes",
  timestamps: true, // 自动维护时间
  freezeTableName: true, // 禁止修改表名，如果不写会把表名自动复数化，users
  paranoid: true, // 软删除
  indexes: [{ unique: true, fields: ["id", "userId"] }],
})
export default class Notes extends Model<Notes> {
  @Column({
    type: DataType.INTEGER.UNSIGNED,
    autoIncrement: true,
    primaryKey: true,
    allowNull: false,
    comment: "记录id",
  })
  id!: number;

  @Column({
    type: new DataType.STRING(128),
    allowNull: false,
    comment: "对应用户唯一标识",
  })
  userId!: string;

  @Column({
    type: new DataType.STRING(128),
    allowNull: false,
    comment: "标题",
  })
  title!: string;

  @Column({
    type: new DataType.STRING(128),
    comment: "笔记描述内容",
  })
  description!: string;

  @Column({
    type: new DataType.TEXT('long'), // longText
    allowNull: false,
    comment: "笔记内容",
  })
  content!: string;

  @Column({
    type: new DataType.STRING(128),
    comment: "相关标签ID JSON字符串数组",
  })
  tagIds!: string;

  @Column({
    type: new DataType.INTEGER({ length: 8 }),
    comment: "星星数量",
    defaultValue: 0,
  })
  star!: number;

  @Column({
    type: new DataType.INTEGER({ length: 8 }),
    comment: "浏览数量",
    defaultValue: 0,
  })
  browseNum!: number;
}